package com.dong.config;
import com.dong.YOLOAPI.imagesrecognize2;
import com.dong.YOLOAPI.imagesrecognize3;
import com.dong.vedio.VideoWebSocketHandler;
import com.dong.vedio.vedio2.Video2WebSocketHandler;
import com.dong.vedio.vedio3.Video3WebSocketHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import  com.dong.YOLOAPI.imagesrecognize1;
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    private final VideoWebSocketHandler videoWebSocketHandler;
    private final Video2WebSocketHandler video2WebSocketHandler;
    private final Video3WebSocketHandler video3WebSocketHandler;
    private final imagesrecognize1 imagesrecognize1;
    private final imagesrecognize2 imagesrecognize2;
    private final imagesrecognize3 imagesrecognize3;
    // 注入所有需要的处理器
    public WebSocketConfig(VideoWebSocketHandler videoWebSocketHandler,
                           Video2WebSocketHandler video2WebSocketHandler,
                           Video3WebSocketHandler video3WebSocketHandler,
                           imagesrecognize1 imagesrecognize1, imagesrecognize2 imagesrecognize2, imagesrecognize3 imagesrecognize3
    ) {
        this.videoWebSocketHandler = videoWebSocketHandler;
        this.video2WebSocketHandler = video2WebSocketHandler;
        this.video3WebSocketHandler = video3WebSocketHandler;
        this.imagesrecognize1 = imagesrecognize1;
        this.imagesrecognize2 = imagesrecognize2;
        this.imagesrecognize3 = imagesrecognize3;
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 为每个路径分配对应的处理器
        registry.addHandler(videoWebSocketHandler, "/video-stream").setAllowedOrigins("*");
        registry.addHandler(video2WebSocketHandler, "/video-stream2").setAllowedOrigins("*");
        registry.addHandler(video3WebSocketHandler, "/video-stream3").setAllowedOrigins("*");
        registry.addHandler(imagesrecognize1, "/image1").setAllowedOrigins("*");
        registry.addHandler(imagesrecognize2, "/image2").setAllowedOrigins("*");
        registry.addHandler(imagesrecognize3, "/image3").setAllowedOrigins("*");
    }
}